<template>
    <div>

        <!-- OA公文系统会议纪要 -->
        <van-pull-refresh v-model="tabRefreshing" @refresh="tableViewRefresh">

            <van-list v-model="tableViewLoading" :finished="tableViewFinished" :finished-text='requestNoMoreMessage'
                :error-text="requestErrorMessage" @load='tableViewLoadMore' style="margin-bottom: 50px;" ref="listRef">

                <van-cell v-for="(item, index) in tableViewDataList" :key="index" @click="cellDidSelectMethod(item)">
                    <div>
                        <div class="titlefont"> 文件标题：{{ item.title }}</div>
                        <div class="infosfont"> 文件字号: {{ item.zihao }}</div>
                    </div>
                </van-cell>

                <!-- 请求第一页数据时，出现错误或无数据 展示空白提示界面
                请求后续数据时，只做弹窗提示 -->
                <div v-show="showEmptyView" class="text-c">
                    <img width="100px" height="100px" :src="require('@/assets/images/pic_nodata.png')" alt="暂无数据"
                        style="margin: 120px 50px 0" @click="tableViewRefresh()" />
                </div>

                <div v-show="showErrorView" class="text-c">
                    <img width="100px" height="100px" :src="require('@/assets/images/pic_neterror.png')" alt="获取数据失败"
                        style="margin: 120px 50px 0" @click="tableViewRefresh()" />
                    <div class="color-b font14" style="margin: 20px 0 0 15px">
                        {{ requestErrorMessage }}
                    </div>
                </div>

            </van-list>
        </van-pull-refresh>
    </div>
</template>

<script>

import { getMeetingListToOfficialDocument } from "@/api/dictapi";
import jDrawupUtil, { ChooseSJ_KEY, Choose_HYJY_KEY, dict_xmbg_code, DrawupChooseType_HYJY } from "../../assets/js/dict_process_helper";
import jTool from "@/assets/js/jHelper";

import { Toast, Dialog } from "vant";
import { Notify } from "vant";
import { mapGetters } from "vuex";
import moment from 'moment'

export default {
    name: 'oa_hyjy_tab',
    data() {
        return {

            currentPage: 1,
            requestParam: {
                page: 1, rows: 10, size: 10,
            },

            requestNoMoreMessage: '',
            requestErrorMessage: '',

            tableViewDataList: [],
            tabRefreshing: true,
            tableViewLoading: false,
            tableViewFinished: false,


        }
    },

    props: ['pushParams'],

    computed: {
        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),

        showEmptyView() {

            return this.requestParam.page === 1 && this.tableViewDataList.length === 0 && !jTool.stringIsEmpty(this.requestErrorMessage);
        },

        showErrorView() {

            return this.requestParam.page === 1 && !jTool.stringIsEmpty(this.requestErrorMessage);
        },
    },

    created() {

    },

    mounted() {

    },

    activated() {


        this.tableViewRefresh()
    },

    methods: {


        // 查询
        requestDataWithFliterCondition(params) {

            Object.assign(this.requestParam, params);
            this.tableViewRefresh();
        },

        tableViewRefresh() {

            this.requestParam.page = 1;

            this.tabRefreshing = true;

            this.tableViewLoading = false;
            this.tableViewFinished = true;
            this.requestListDatas();
        },

        tableViewLoadMore() {

            if (!jTool.stringIsEmpty(this.requestNoMoreMessage)) {

                this.tableViewLoading = false
                this.tableViewFinished = true;
            }
            else {

                this.tabRefreshing = false;
                this.requestListDatas();
            }
        },

        requestListDatas() {

            getMeetingListToOfficialDocument(this.requestParam)
                .then((result) => {

                    if (!result.data) {
                        this.tableViewFinished = true;
                        this.requestCompletion('result.message');
                        return;
                    }

                    let listdetails = [];
                    if (result.data.data.content) {
                        listdetails = listdetails.concat(result.data.data.content);
                    }

                    if (this.requestParam.page == 1) {
                        this.tableViewDataList = listdetails;
                    }
                    else {
                        this.tableViewDataList = this.tableViewDataList.concat(listdetails);
                    }

                    if (result.data.data.totalPages <= this.requestParam.page) {
                        this.requestNoMoreMessage = '没有更多数据！';
                        this.tableViewFinished = true;
                    }
                    else {
                        this.requestParam.page++;
                        this.requestNoMoreMessage = '';
                        this.tableViewFinished = false;
                    }

                    this.requestCompletion('');
                })
                .catch((error) => {
                    this.tableViewFinished = true;
                    this.requestCompletion('获取数据失败,请稍后重试');
                });
        },


        requestCompletion(error) {

            this.tabRefreshing = false;
            this.tableViewLoading = false

            if (!jTool.stringIsEmpty(error)) {
                this.requestErrorMessage = error;
                Notify({ type: 'warning', message: error })
            }
        },

        timeUtil(value) {
            return moment(value).format('YYYY-MM-DD HH:mm:ss');
        },




        cellDidSelectMethod(value) {

            localStorage.setItem(Choose_HYJY_KEY, JSON.stringify(value));
            this.$router.back(-1);
        }
    }
}
</script>

<style scoped></style>